home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / PROGTOOL / VCRPLUS.ZIP;1 / DECODE.C next >
Encoding:
C/C++ Source or Header  |  1992-12-31  |  14.2 KB  |  744 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>     // for exit() and atol()
  3.  
  4. #define        KEY001    (68150631L)
  5. #define        INVALID    (-987L)
  6.  
  7.  
  8. /* function that performs initial scrambling */
  9. long     mixup(long x, long y)
  10. {
  11.     long     i, j, k, sum;
  12.  
  13.     long     a[12], b[12], out[12] ;
  14.  
  15.     /* get the digits of x into a[] */
  16.     j = x ;
  17.     for(i=0; i<9; i++)
  18.     {
  19.         k = j % 10;
  20.         a[i] = k;
  21.         j = (j - k) / 10 ;
  22.     }
  23.  
  24.     /* get the digits of y into b[] */
  25.     j = y ;
  26.     for(i=0; i<9; i++)
  27.     {
  28.         k = j % 10;
  29.         b[i] = k;
  30.         j = (j - k) / 10 ;
  31.         out[i] = 0;
  32.     }
  33.  
  34.  
  35.     for(i=0; i<=8; i++)
  36.     {
  37.         for(j=0; j<=8; j++)
  38.         {
  39.             out[i+j] += (b[j] * a[i]) ;
  40.         }
  41.     }
  42.  
  43.     j = 1;
  44.     sum = 0;
  45.     for(i=0; i<=8; i++)
  46.     {
  47.         sum += j * (out[i] % 10);
  48.         j = j * 10 ;
  49.     }
  50.     return( sum ) ;
  51. }
  52.  
  53.  
  54.  
  55. /* first function */
  56. long     f1(long inval)
  57. {
  58.     long     ndigits, hashval ;
  59.     long     pwr ;
  60.  
  61.  
  62.     ndigits = 0;
  63.     pwr = 1;
  64.     while(inval >= pwr) { ndigits++; pwr *= 10; }
  65.     if(ndigits > 8) printf("\nPANIC: %ld has %ld digits\n", inval, ndigits);
  66.     pwr = pwr / 10 ;
  67.  
  68.     hashval = inval;
  69. again:    hashval = mixup(hashval, KEY001) % (pwr * 10) ;
  70.     if(hashval < pwr) goto again ;
  71.  
  72.     return(hashval);
  73. }
  74.  
  75.  
  76.  
  77.  
  78. /* the 512-entry tables of starting time and pgm duration */
  79. void    lookup(long i, long *outtime, long *outdur)
  80. {
  81.     static    long     start[480], leng[480] ;
  82.     static    long     initializer = 0;
  83.  
  84.     long     j, s;
  85.  
  86.     if(initializer == 0) {
  87.     initializer = 1;
  88.  
  89.     for(j=0; j<512; j++) { start[j] = leng[j] = INVALID; }
  90.  
  91.     leng[0]   =  30 ;
  92.     leng[100] = 120 ;
  93.     leng[101] =  90 ;
  94.     leng[102] = 120 ;
  95.     leng[103] = 120 ;
  96.     leng[104] =  90 ;
  97.     leng[105] =  90 ;
  98.     leng[106] =  30 ;
  99.     leng[107] =  30 ;
  100.     leng[108] = 120 ;
  101.     leng[109] =  90 ;
  102.     leng[10]  =  30 ;
  103.     leng[110] =  90 ;
  104.     leng[111] =  30 ;
  105.     leng[112] =  90 ;
  106.     leng[113] =  30 ;
  107.     leng[114] =  30 ;
  108.     leng[115] = 120 ;
  109.     leng[116] =  30 ;
  110.     leng[117] = 120 ;
  111.     leng[118] = 120 ;
  112.     leng[119] =  30 ;
  113.     leng[11]  =  30 ;
  114.     leng[120] =  90 ;
  115.     leng[121] =  60 ;
  116.     leng[122] =  60 ;
  117.     leng[123] =  60 ;
  118.     leng[124] = 120 ;
  119.     leng[125] =  90 ;
  120.     leng[126] =  60 ;
  121.     leng[127] =  60 ;
  122.     leng[128] =  90 ;
  123.     leng[129] = 120 ;
  124.     leng[12]  =  30 ;
  125.     leng[130] = 120 ;
  126.     leng[131] =  90 ;
  127.     leng[132] =  60 ;
  128.     leng[133] =  60 ;
  129.     leng[134] = 120 ;
  130.     leng[135] =  90 ;
  131.     leng[136] =  90 ;
  132.     leng[137] = 120 ;
  133.     leng[138] = 120 ;
  134.     leng[139] =  60 ;
  135.     leng[13]  = 120 ;
  136.     leng[140] =  60 ;
  137.     leng[141] =  90 ;
  138.     leng[142] =  90 ;
  139.     leng[143] = 120 ;
  140.     leng[144] =  90 ;
  141.     leng[145] = 120 ;
  142.     leng[146] =  90 ;
  143.     leng[147] = 120 ;
  144.     leng[148] = 120 ;
  145.     leng[149] =  90 ;
  146.     leng[14]  =  30 ;
  147.     leng[150] = 120 ;
  148.     leng[151] =  90 ;
  149.     leng[152] =  90 ;
  150.     leng[153] =  90 ;
  151.     leng[154] =  60 ;
  152.     leng[155] =  60 ;
  153.     leng[156] = 120 ;
  154.     leng[157] =  60 ;
  155.     leng[158] =  60 ;
  156.     leng[159] =  60 ;
  157.     leng[15]  =  30 ;
  158.     leng[160] = 120 ;
  159.     leng[161] =  60 ;
  160.     leng[162] =  90 ;
  161.     leng[163] =  90 ;
  162.     leng[164] =  60 ;
  163.     leng[165] =  90 ;
  164.     leng[166] =  90 ;
  165.     leng[167] =  60 ;
  166.     leng[168] =  90 ;
  167.     leng[169] = 120 ;
  168.     leng[16]  = 120 ;
  169.     leng[170] =  60 ;
  170.     leng[171] = 120 ;
  171.     leng[172] =  60 ;
  172.     leng[173] =  60 ;
  173.     leng[174] = 120 ;
  174.     leng[175] =  90 ;
  175.     leng[176] =  60 ;
  176.     leng[177] = 120 ;
  177.     leng[178] =  60 ;
  178.     leng[179] =  60 ;
  179.     leng[17]  = 120 ;
  180.     leng[180] =  60 ;
  181.     leng[181] =  90 ;
  182.     leng[182] =  60 ;
  183.     leng[183] = 120 ;
  184.     leng[184] =  60 ;
  185.     leng[185] =  60 ;
  186.     leng[186] =  90 ;
  187.     leng[187] =  60 ;
  188.     leng[188] =  90 ;
  189.     leng[189] = 120 ;
  190.     leng[18]  =  60 ;
  191.     leng[190] =  90 ;
  192.     leng[191] =  90 ;
  193.     leng[19]  = 120 ;
  194.     leng[1]   =  30 ;
  195.     leng[20]  =  60 ;
  196.     leng[21]  =  60 ;
  197.     leng[22]  =  60 ;
  198.     leng[23]  = 120 ;
  199.     leng[24]  =  60 ;
  200.     leng[25]  = 120 ;
  201.     leng[26]  =  30 ;
  202.     leng[27]  =  30 ;
  203.     leng[28]  =  30 ;
  204.     leng[29]  =  60 ;
  205.     leng[2]   =  30 ;
  206.     leng[30]  =  90 ;
  207.     leng[31]  =  30 ;
  208.     leng[32]  =  30 ;
  209.     leng[33]  =  30 ;
  210.     leng[34]  =  30 ;
  211.     leng[35]  =  60 ;
  212.     leng[36]  =  30 ;
  213.     leng[37]  =  60 ;
  214.     leng[38]  = 120 ;
  215.     leng[39]  =  60 ;
  216.     leng[3]   =  30 ;
  217.     leng[40]  =  30 ;
  218.     leng[41]  =  30 ;
  219.     leng[42]  =  30 ;
  220.     leng[43]  =  30 ;
  221.     leng[44]  = 120 ;
  222.     leng[45]  =  30 ;
  223.     leng[46]  =  30 ;
  224.     leng[47]  =  30 ;
  225.     leng[48]  = 120 ;
  226.     leng[49]  =  30 ;
  227.     leng[4]   =  30 ;
  228.     leng[50]  =  60 ;
  229.     leng[51]  =  60 ;
  230.     leng[52]  =  30 ;
  231.     leng[53]  =  30 ;
  232.     leng[54]  = 120 ;
  233.     leng[55]  =  60 ;
  234.     leng[56]  =  60 ;
  235.     leng[57]  =  30 ;
  236.     leng[58]  = 120 ;
  237.     leng[59]  =  30 ;
  238.     leng[5]   =  30 ;
  239.     leng[60]  = 120 ;
  240.     leng[61]  = 120 ;
  241.     leng[62]  = 120 ;
  242.     leng[63]  =  30 ;
  243.     leng[64]  =  90 ;
  244.     leng[65]  =  30 ;
  245.     leng[66]  =  30 ;
  246.     leng[67]  =  30 ;
  247.     leng[68]  = 120 ;
  248.     leng[69]  =  90 ;
  249.     leng[6]   =  30 ;
  250.     leng[70]  =  90 ;
  251.     leng[71]  =  60 ;
  252.     leng[72]  =  90 ;
  253.     leng[73]  =  90 ;
  254.     leng[74]  =  90 ;
  255.     leng[75]  =  90 ;
  256.     leng[76]  =  90 ;
  257.     leng[77]  =  60 ;
  258.     leng[78]  =  90 ;
  259.     leng[79]  =  30 ;
  260.     leng[7]   =  30 ;
  261.     leng[80]  = 120 ;
  262.     leng[81]  =  60 ;
  263.     leng[82]  =  90 ;
  264.     leng[83]  = 120 ;
  265.     leng[84]  =  60 ;
  266.     leng[85]  =  60 ;
  267.     leng[86]  = 120 ;
  268.     leng[87]  =  30 ;
  269.     leng[88]  =  90 ;
  270.     leng[89]  = 120 ;
  271.     leng[8]   =  30 ;
  272.     leng[90]  = 120 ;
  273.     leng[91]  =  90 ;
  274.     leng[92]  =  90 ;
  275.     leng[93]  =  90 ;
  276.     leng[94]  =  90 ;
  277.     leng[95]  = 120 ;
  278.     leng[96]  =  60 ;
  279.     leng[97]  = 120 ;
  280.     leng[98]  =  90 ;
  281.     leng[99]  =  30 ;
  282.     leng[9]   =  60 ;
  283.     start[0]   = 1830 ;
  284.     start[100] =  330 ;
  285.     start[101] = 1500 ;
  286.     start[102] = 1500 ;
  287.     start[103] = 2300 ;
  288.     start[104] = 1900 ;
  289.     start[105] =  800 ;
  290.     start[106] =  430 ;
  291.     start[107] =  300 ;
  292.     start[108] = 1330 ;
  293.     start[109] = 1000 ;
  294.     start[10]  = 1400 ;
  295.     start[110] =  700 ;
  296.     start[111] =  100 ;
  297.     start[112] = 2330 ;
  298.     start[113] =  330 ;
  299.     start[114] =  200 ;
  300.     start[115] = 2230 ;
  301.     start[116] =  400 ;
  302.     start[117] =  600 ;
  303.     start[118] =  400 ;
  304.     start[119] =  230 ;
  305.     start[11]  = 2030 ;
  306.     start[120] =  630 ;
  307.     start[121] =   30 ;
  308.     start[122] = 2230 ;
  309.     start[123] =  100 ;
  310.     start[124] =   30 ;
  311.     start[125] = 2300 ;
  312.     start[126] = 1630 ;
  313.     start[127] =  830 ;
  314.     start[128] =    0 ;
  315.     start[129] = 1930 ;
  316.     start[12]  = 1700 ;
  317.     start[130] =  930 ;
  318.     start[131] = 2030 ;
  319.     start[132] =  500 ;
  320.     start[133] = 1730 ;
  321.     start[134] =  200 ;
  322.     start[135] = 1930 ;
  323.     start[136] =  930 ;
  324.     start[137] = 1730 ;
  325.     start[138] =  630 ;
  326.     start[139] = 1830 ;
  327.     start[13]  = 1600 ;
  328.     start[140] = 1430 ;
  329.     start[141] = 1130 ;
  330.     start[142] =   30 ;
  331.     start[143] =  830 ;
  332.     start[144] = 1030 ;
  333.     start[145] = 1430 ;
  334.     start[146] =  100 ;
  335.     start[147] =  730 ;
  336.     start[148] = 2030 ;
  337.     start[149] =  300 ;
  338.     start[14]  = 2000 ;
  339.     start[150] =  300 ;
  340.     start[151] = 1330 ;
  341.     start[152] = 1230 ;
  342.     start[153] =  230 ;
  343.     start[154] = 2130 ;
  344.     start[155] = 1130 ;
  345.     start[156] = 1830 ;
  346.     start[157] =  630 ;
  347.     start[158] =  530 ;
  348.     start[159] =  200 ;
  349.     start[15]  = 1500 ;
  350.     start[160] = 1530 ;
  351.     start[161] =  730 ;
  352.     start[162] =  600 ;
  353.     start[163] = 1730 ;
  354.     start[164] =  400 ;
  355.     start[165] =  730 ;
  356.     start[166] =  430 ;
  357.     start[167] =  430 ;
  358.     start[168] =  130 ;
  359.     start[169] = 1230 ;
  360.     start[16]  = 2000 ;
  361.     start[170] =  130 ;
  362.     start[171] =  230 ;
  363.     start[172] = 1930 ;
  364.     start[173] =  300 ;
  365.     start[174] = 1030 ;
  366.     start[175] =  200 ;
  367.     start[176] =  330 ;
  368.     start[177] =  500 ;
  369.     start[178] =  930 ;
  370.     start[179] =  230 ;
  371.     start[17]  = 2100 ;
  372.     start[180] = 2030 ;
  373.     start[181] =  400 ;
  374.     start[182] = 1530 ;
  375.     start[183] =  430 ;
  376.     start[184] = 1330 ;
  377.     start[185] = 1230 ;
  378.     start[186] =  330 ;
  379.     start[187] = 1030 ;
  380.     start[188] =  500 ;
  381.     start[189] =  530 ;
  382.     start[18]  = 2000 ;
  383.     start[190] =  530 ;
  384.     start[191] = 1100 ;
  385.     start[19]  = 1800 ;
  386.     start[1]   = 1600 ;
  387.     start[20]  = 1900 ;
  388.     start[21]  = 2200 ;
  389.     start[22]  = 2100 ;
  390.     start[23]  = 1400 ;
  391.     start[24]  = 1500 ;
  392.     start[25]  = 2200 ;
  393.     start[26]  = 1130 ;
  394.     start[27]  = 1100 ;
  395.     start[28]  = 2300 ;
  396.     start[29]  = 1600 ;
  397.     start[2]   = 1930 ;
  398.     start[30]  = 2100 ;
  399.     start[31]  = 2100 ;
  400.     start[32]  = 1230 ;
  401.     start[33]  = 1330 ;
  402.     start[34]  =  930 ;
  403.     start[35]  = 1300 ;
  404.     start[36]  = 2130 ;
  405.     start[37]  = 1200 ;
  406.     start[38]  = 1000 ;
  407.     start[39]  = 1800 ;
  408.     start[3]   = 1630 ;
  409.     start[40]  = 2200 ;
  410.     start[41]  = 1200 ;
  411.     start[42]  =  800 ;
  412.     start[43]  =  830 ;
  413.     start[44]  = 1700 ;
  414.     start[45]  =  900 ;
  415.     start[46]  = 2230 ;
  416.     start[47]  = 1030 ;
  417.     start[48]  = 1900 ;
  418.     start[49]  =  730 ;
  419.     start[4]   = 1530 ;
  420.     start[50]  = 2300 ;
  421.     start[51]  = 1000 ;
  422.     start[52]  =  700 ;
  423.     start[53]  = 1300 ;
  424.     start[54]  =  700 ;
  425.     start[55]  = 1100 ;
  426.     start[56]  = 1400 ;
  427.     start[57]  = 1000 ;
  428.     start[58]  =  800 ;
  429.     start[59]  = 2330 ;
  430.     start[5]   = 1730 ;
  431.     start[60]  = 1300 ;
  432.     start[61]  = 1200 ;
  433.     start[62]  =  900 ;
  434.     start[63]  =  630 ;
  435.     start[64]  = 1800 ;
  436.     start[65]  =  600 ;
  437.     start[66]  =  530 ;
  438.     start[67]  =    0 ;
  439.     start[68]  = 2330 ;
  440.     start[69]  = 2200 ;
  441.     start[6]   = 1800 ;
  442.     start[70]  = 1300 ;
  443.     start[71]  =  900 ;
  444.     start[72]  = 1630 ;
  445.     start[73]  = 1600 ;
  446.     start[74]  = 1430 ;
  447.     start[75]  = 2000 ;
  448.     start[76]  = 1830 ;
  449.     start[77]  =  600 ;
  450.     start[78]  = 1200 ;
  451.     start[79]  =   30 ;
  452.     start[7]   = 1430 ;
  453.     start[80]  =  130 ;
  454.     start[81]  =    0 ;
  455.     start[82]  = 1700 ;
  456.     start[83]  =    0 ;
  457.     start[84]  =  800 ;
  458.     start[85]  =  700 ;
  459.     start[86]  = 2130 ;
  460.     start[87]  =  500 ;
  461.     start[88]  = 1530 ;
  462.     start[89]  = 1130 ;
  463.     start[8]   = 1900 ;
  464.     start[90]  = 1100 ;
  465.     start[91]  =  830 ;
  466.     start[92]  = 2230 ;
  467.     start[93]  =  900 ;
  468.     start[94]  = 2130 ;
  469.     start[95]  = 1630 ;
  470.     start[96]  = 2330 ;
  471.     start[97]  =  100 ;
  472.     start[98]  = 1400 ;
  473.     start[99]  =  130 ;
  474.     start[9]   = 1700 ;
  475.  
  476.  
  477.     s = 2330;
  478.     for(j=192; j<240; j++)
  479.     { start[j] = s; leng[j] = 150; if(0==(j%2)) s-=30; else s-=70; }
  480.  
  481.     s = 2330;
  482.     for(j=240; j<288; j++)
  483.     { start[j] = s; leng[j] = 180; if(0==(j%2)) s-=30; else s-=70; }
  484.  
  485.     s = 2330;
  486.     for(j=288; j<336; j++)
  487.     { start[j] = s; leng[j] = 210; if(0==(j%2)) s-=30; else s-=70; }
  488.  
  489.     s = 2330;
  490.     for(j=336; j<384; j++)
  491.     { start[j] = s; leng[j] = 240; if(0==(j%2)) s-=30; else s-=70; }
  492.  
  493.     s = 2330;
  494.     for(j=384; j<432; j++)
  495.     { start[j] = s; leng[j] = 270; if(0==(j%2)) s-=30; else s-=70; }
  496.  
  497.     s = 2330;
  498.     for(j=432; j<480; j++)
  499.     { start[j] = s; leng[j] = 300; if(0==(j%2)) s-=30; else s-=70; }
  500.  
  501.     } /* end of initializer block */
  502.  
  503.  
  504.  
  505.     if((i >= 480) || (i < 0))
  506.         printf("\nPANIC, Illegal table index %ld\n", i);
  507.  
  508.     fflush(stdout);
  509.     *outtime = (start[i]) ;
  510.     *outdur = (leng[i]) ;
  511.  
  512.     if( (*outtime == INVALID) || (*outdur == INVALID) )
  513.     {
  514.         printf("oops, I dont have an entry for index %ld\n", i);
  515.         fflush(stdout);
  516.         *outtime = 0;
  517.         *outdur = 0;
  518.     }
  519. }
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526. void    bit_shuffle(long t8c5, long t2c1, long *tval, long *cval)
  527. {
  528.     long     tt, cc, b;
  529.  
  530.     tt = 0 ;
  531.     cc = 0 ;
  532.  
  533.     /* get t8 thru t3 */
  534.     b = 0x00000001 & (t8c5 >> 9) ;
  535.     tt += (b << 8);
  536.  
  537.     b = 0x00000001 & (t8c5 >> 7) ;
  538.     tt += (b << 7);
  539.  
  540.     b = 0x00000001 & (t8c5 >> 5) ;
  541.     tt += (b << 6);
  542.  
  543.     b = 0x00000001 & (t8c5 >> 4) ;
  544.     tt += (b << 5);
  545.  
  546.     b = 0x00000001 & (t8c5 >> 3) ;
  547.     tt += (b << 4);
  548.  
  549.     b = 0x00000001 & t8c5 ;
  550.     tt += (b << 3);
  551.  
  552.  
  553.     /* get c5 thru c2 */
  554.     b = 0x00000001 & (t8c5 >> 8) ;
  555.     cc += (b << 5);
  556.  
  557.     b = 0x00000001 & (t8c5 >> 6) ;
  558.     cc += (b << 4);
  559.  
  560.     b = 0x00000001 & (t8c5 >> 2) ;
  561.     cc += (b << 3);
  562.  
  563.     b = 0x00000001 & (t8c5 >> 1) ;
  564.     cc += (b << 2) ;
  565.  
  566.  
  567.     /* get t2 thru t0 */
  568.     b = 0x00000001 & (t2c1 >> 4) ;
  569.     tt += (b << 2);
  570.  
  571.     b = 0x00000001 & (t2c1 >> 2) ;
  572.     tt += (b << 1);
  573.  
  574.     b = 0x00000001 & t2c1 ;
  575.     tt += b;
  576.  
  577.  
  578.     /* get c1 thru c0 */
  579.     b = 0x00000001 & (t2c1 >> 3) ;
  580.     cc += (b << 1);
  581.  
  582.     b = 0x00000001 & (t2c1 >> 1) ;
  583.     cc += b ;
  584.  
  585.     *tval = tt;
  586.     *cval = cc;
  587. }
  588.  
  589.  
  590.  
  591.  
  592.  
  593. long     map_top(long day, long year, long top, long digits)
  594. {
  595.     long     d2, d1, d0, y, poot ;
  596.     long     n2, n1, n0, f3, f2, f1, f0;
  597.  
  598.     y = year % 16 ;
  599.     d2 = top / 100 ;
  600.     d1 = (top % 100) / 10 ;
  601.     d0 = top % 10 ;
  602.  
  603.     f0 = 1;
  604.     f1 = (y + 1) % 10;
  605.     f2 = ( ((y+1)*(y+2)) / 2 ) % 10 ;
  606.     f3 = ( ((y+1)*(y+2)*(y+3)) / 6 ) % 10 ;
  607.  
  608.  
  609.     if(digits == 1)
  610.     {
  611.         n0 = ( (d0*f0) + (day*f1) ) % 10 ;
  612.         n1 = 0;
  613.         n2 = 0;
  614.     }
  615.  
  616.     if(digits == 2)
  617.     {
  618.         n0 = ( (d0*f0) + (d1*f1) + (day*f2) ) % 10 ;
  619.         n1 = ( (d1*f0) + (day*f1) ) % 10 ;
  620.         n2 = 0;
  621.     }
  622.  
  623.     if(digits == 3)
  624.     {
  625.         n0 = ( (d0*f0) + (d1*f1) + (d2*f2) + (day*f3) ) % 10 ;
  626.         n1 = ( (d1*f0) + (d2*f1) + (day*f2) ) % 10 ;
  627.         n2 = ( (d2*f0) + (day*f1) ) % 10 ;
  628.     }
  629.  
  630.  
  631.     poot =  (100*n2) + (10*n1) + n0 ;
  632.  
  633.     return( poot );
  634. }
  635.  
  636.  
  637.  
  638.  
  639.  
  640.  
  641. void    offset(long day, long year, long top, long *ofout, long *topout)
  642. {
  643.     long     i, t, tx, off, digits, burp;
  644.     long     pwr ;
  645.  
  646.     pwr = 1 ; digits = 0;
  647.     while(top >= pwr) { digits++; pwr *= 10; }
  648.     pwr = pwr / 10 ;
  649.  
  650.     t = tx = top ;
  651.     off = 0;
  652.     while(tx > 0) { off += (tx % 10);   tx /= 10; }
  653.  
  654. again:
  655.     for(i=0; i<=(year%16); i++)
  656.         {
  657.         burp = ( (map_top(day, i, t, digits)) % 10 ) ;
  658.         off += burp ;
  659.         }
  660.  
  661.     t = map_top(day, year, t, digits) ;
  662.     if(t < pwr) goto again ;
  663.  
  664.  
  665.     *ofout = (off % 32) ;
  666.     *topout = (t) ;
  667. }
  668.  
  669.  
  670.  
  671.  
  672.  
  673.  
  674.  
  675.  
  676.  
  677.  
  678. main(int argc, char *argv[])
  679. {
  680.     long     newspaper ;
  681.     long     s1_out, bot3, top5, quo, rem ;
  682.     long     s5_out, mtout, ofout, tval, cval ;
  683.     long     date_today, month_today, year_today ;
  684.     long     day_out, channel_out;
  685.     long     starttime_out, duration_out ;
  686.  
  687.  
  688.  
  689.     if(argc == 5) goto clean;
  690.  
  691. upchuck:
  692.     printf("Usage: %s  todays_month  todays_day  todays_year   Code_value_in_newspaper\n",
  693.         argv[0]);
  694.     exit(-1) ;
  695.  
  696.  
  697.  
  698. clean:
  699.  
  700.     month_today = atol(argv[1]);
  701.     date_today = atol(argv[2]);
  702.     year_today = atol(argv[3]);
  703.     newspaper = atol(argv[4]);
  704.  
  705.     year_today = year_today % 100 ;
  706.  
  707.  
  708.     if( (month_today>12) || (month_today<1) || (date_today<1) || (date_today>31) )
  709.     { printf("Invalid date\n"); goto upchuck; }
  710.  
  711.     if((newspaper < 1) || (newspaper > 999999L))
  712.     { printf("Sorry, I cant process that code value\n  I can only do codes with 6 digits or fewer\n"); goto upchuck; }
  713.  
  714.  
  715.  
  716.  
  717.     ofout = INVALID ;
  718.     mtout = INVALID ;
  719.  
  720.     s1_out = f1(newspaper);
  721.     bot3 = s1_out % 1000;
  722.     top5 = s1_out / 1000;
  723.     quo = (bot3 - 1) / 32 ;
  724.     rem = (bot3 - 1) % 32 ;
  725.     day_out = quo + 1;
  726.  
  727.     if(newspaper >= 1000)
  728.         offset(day_out, year_today, top5, (&ofout), (&mtout)) ;
  729.     else { mtout = 0; ofout = 0; }
  730.  
  731.     s5_out = (rem + (day_out*(month_today+1)) + ofout) % 32 ;
  732.  
  733.  
  734.     bit_shuffle(mtout, s5_out, &tval, &cval);
  735.     channel_out = cval + 1;
  736.     lookup(tval, (&starttime_out), (&duration_out));
  737.  
  738.     printf("Code= %6ld    %2ld  %2ld  %2ld   Mapped_channel= %2ld  Start_time= %4ld  Length= %3ld\n",
  739.         newspaper, month_today, day_out, year_today, channel_out, starttime_out, duration_out);
  740.     return(0);
  741. }
  742.  
  743.  
  744.